{% extends "layout.html" %}
{% block head%}
{{super()}}
{% endblock %}
{% block content %}
<div class="container">
<h1>Registered users</h1>
<table id="table-users" class="table table-striped">
<thead>
    <tr>
        <th>#</th>
        <th>Login</th>
        <th>Member since</th>
        <th>Last seen</th>
        <th>Actions</th>
    </tr>
</thead>
<tbody>
{% for user in users %}
    <tr {% if not user.is_active  %}class="warning"{% endif %}>
        <td><a href="{{ url_for("admin_bp.form_user", user_id=user.id) }}">{{ loop.index }}</a></td>
        <td>{{ user.login  }}</td>
        <td class="date">{{ user.created_at }}</td>
        <td class="date">{{ user.last_seen }}</td>
        <td>
            {% if user.id != current_user.id %}
                <a href="{{ url_for("admin_bp.toggle_user", user_id=user.id) }}">
                {% if user.is_active %}
                    <i class="glyphicon glyphicon-ban-circle" title="Disable this account"></i>
                {% else %}
                    <i class="glyphicon glyphicon-ok-circle" title="Enable this account"></i>
                {% endif %}
                </a>
                <a href="{{ url_for("admin_bp.delete_user", user_id=user.id) }}"><i class="glyphicon glyphicon-remove" title="Delete this user" onclick="return confirm('You are going to delete this account.');"></i></a>
            {% endif %}
        </td>
    </tr>
{% endfor %}
</tbody>
</table>
<a href="{{ url_for('admin_bp.form_user') }}" class="btn btn-default">Add a new user</a>
</div>
<script>
$(document).ready(function() {
$('#table-users').DataTable( {
    responsive: true,
    columnDefs: [
        {
            bSortable: false,
            targets: [0, 5]
        }
    ]
});
});
</script>
{% endblock %}
